(DEFUN C:RENAMEORTHOS ()
  (IF USTR NIL (LOAD "USTR" "\nFile USTR.LSP not loaded! "))
  (SETQ orthoprefix (ustr 1 "Enter filename prefix to rename, do not include extensions (~ for none)" (if orthoprefix (IF (WCMATCH orthoprefix "") "~" orthoprefix)) T))
  (IF (WCMATCH orthoprefix "`~")
    (SETQ orthoprefix "")
  )
  (SETQ orthosuffix (ustr 1 "Enter filename suffix to rename, do not include extensions (~ for none)" (if orthosuffix (IF (WCMATCH orthosuffix "") "~" orthosuffix)) T))
  (IF (WCMATCH orthosuffix "`~")
    (SETQ orthosuffix "")
  )
  (SETQ orthopath (DOS_GETDIR "Select SID File Folder" "W:\\Shapefiles\\" "Files matching the filename pattern will be renamed"))
  (SETQ orthofiles (DOS_DIR (STRCAT orthopath orthoprefix "*" (IF (AND orthosuffix (/= orthosuffix ""))(STRCAT orthosuffix "*.*") ".*"))))
  (FOREACH n orthofiles
    (IF (WCMATCH n (STRCAT orthoprefix "*" orthosuffix ".*"))
      (PROGN
        (SETQ dstrt (DOS_STRTOKENS n "."))
           (COND ((AND orthoprefix (NOT (WCMATCH orthoprefix "")) orthosuffix (NOT (WCMATCH orthosuffix "")))
                  (DOS_RENAME
                    (STRCAT orthopath n)
                    (STRCAT orthopath
                            (SUBSTR (SUBSTR n 1 (-(STRLEN (CAR dstrt))(STRLEN orthosuffix))) (1+ (STRLEN orthoprefix)))
                            "."
                            (IF (EQ (LENGTH dstrt) 3) (STRCAT (IF (= (NTH 1 dstrt) "tif") "sid" (NTH 1 dstrt)) "." (NTH 2 dstrt)) (COND ((=(NTH 1 dstrt)"tif")"sid")((=(NTH 1 dstrt)"tfw")"sdw")(T (NTH 1 dstrt))))
                    )
                  ))
                 ((AND orthoprefix (NOT (WCMATCH orthoprefix "")))
                  (DOS_RENAME
                    (STRCAT orthopath n)
                    (STRCAT orthopath
                            (SUBSTR (SUBSTR n 1 (STRLEN (CAR dstrt))) (1+ (STRLEN orthoprefix)))
                            "."
                            (IF (EQ (LENGTH dstrt) 3) (STRCAT (IF (= (NTH 1 dstrt) "tif") "sid" (NTH 1 dstrt)) "." (NTH 2 dstrt)) (COND ((=(NTH 1 dstrt)"tif")"sid")((=(NTH 1 dstrt)"tfw")"sdw")(T (NTH 1 dstrt))))
                    )
                  ))
                 ((AND orthosuffix (NOT (WCMATCH orthosuffix "")))
                  (DOS_RENAME
                    (STRCAT orthopath n)
                    (STRCAT orthopath
                            (SUBSTR n 1 (-(STRLEN (CAR dstrt))(STRLEN orthosuffix)))
                            "."
                            (IF (EQ (LENGTH dstrt) 3) (STRCAT (IF (= (NTH 1 dstrt) "tif") "sid" (NTH 1 dstrt)) "." (NTH 2 dstrt)) (COND ((=(NTH 1 dstrt)"tif")"sid")((=(NTH 1 dstrt)"tfw")"sdw")(T (NTH 1 dstrt))))
                    )
                  ))
                 ((AND (WCMATCH orthoprefix "") (WCMATCH orthosuffix "")(NOT (WCMATCH n "*.sid,*.sid.ovr,*.sdw")))
                  (DOS_RENAME
                    (STRCAT orthopath n)
                    (STRCAT orthopath
                            (CAR dstrt)
                            "."
                            (IF (EQ (LENGTH dstrt) 3) (STRCAT (IF (= (NTH 1 dstrt) "tif") "sid" (NTH 1 dstrt)) "." (NTH 2 dstrt)) (COND ((=(NTH 1 dstrt)"tif")"sid")((=(NTH 1 dstrt)"tfw")"sdw")(T (NTH 1 dstrt))))
                    )
                  ))
           )
      )
    )
  )
;;;Rockingham County were of this pattern: "OC6i0_37_000_10790501_20100518R0.tfw" this program written to remove "OC6i0_37_000_" and "_20100518R0" from the names.
  (PRINC)
)